<pre>
<font color="#444444">#
# The GoF Decorator pattern
# written by Matthieu Tanguay-Carel
#
# This pattern is made trivial by Ruby's meta methods.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

</font><strong>module</strong> Bordered
    attr_accessor <font color="4444FF">:</font>color
    attr_accessor <font color="4444FF">:</font>width
<strong>end</strong>

<strong>module</strong> Scrollable
    <strong>def<font color="ff0000"> position</font></strong>
        <font color="#2040a0">@position</font> ||<font color="4444FF">=</font> <font color="#FF0000">0</font>
    <strong>end</strong>
    <strong>def<font color="ff0000"> scroll</font></strong> offset
        <font color="#2040a0">@position</font> <font color="4444FF">=</font> position <font color="4444FF">+</font> offset
    <strong>end</strong>
<strong>end</strong>

<strong>class<font color="#2040a0"><strong> Widget</strong></font></strong>
    attr_accessor <font color="4444FF">:</font>content
    <strong>def<font color="ff0000"> initialize</font></strong> content
        <font color="#2040a0">@content</font> <font color="4444FF">=</font> content
    <strong>end</strong>
<strong>end</strong>

<strong>if</strong> __FILE__ <font color="4444FF">==</font> <font color="#2040a0"><strong>$0</strong></font>
    widget <font color="4444FF">=</font> Widget.new <font color="#008000">&quot;flagada jones&quot;</font>
    widget.extend<font color="4444FF"><strong>(</strong></font>Bordered<font color="4444FF"><strong>)</strong></font>
    widget.color <font color="4444FF">=</font> <font color="4444FF">:</font>blue

    widget.extend<font color="4444FF"><strong>(</strong></font>Scrollable<font color="4444FF"><strong>)</strong></font>
    widget.scroll <font color="#FF0000">3</font>

    <font color="a52a2a"><strong>puts</strong></font> widget.kind_of?<font color="4444FF"><strong>(</strong></font>Scrollable<font color="4444FF"><strong>)</strong></font>
    <font color="a52a2a"><strong>puts</strong></font> widget.kind_of?<font color="4444FF"><strong>(</strong></font>Bordered<font color="4444FF"><strong>)</strong></font>
<strong>end</strong>

<br/>
<strong>Output</strong>
<strong>------</strong>
<br/>
true
true
</pre>
